package com.example.Administrator.shoujiweishi.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.example.Administrator.shoujiweishi.MyApplication;
import com.example.Administrator.shoujiweishi.R;
import com.example.Administrator.shoujiweishi.activities.base.BaseActivity;
import com.example.Administrator.shoujiweishi.fragments.UpdataVersionDialogFragment;
import com.example.Administrator.shoujiweishi.vo.VersionInfo;

public class Activity_Update extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar_Update);
        setSupportActionBar(toolbar);
        ActionBar actionBar=getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public int getContentXML() {
        return R.layout.activity__update;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        findViewById(R.id.updata_version).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        startActivityForResult(new Intent(this,UpData_Version.class),0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                Toast.makeText(this, "有网络", Toast.LENGTH_SHORT).show();
                showDialog("有网络，但无法连接到服务器");
                break;
            case 2:
                Toast.makeText(this, "没网了。。", Toast.LENGTH_SHORT).show();
                showDialog("无网络");
                break;
            case 3:
                VersionInfo versionInfo= (VersionInfo) data.getSerializableExtra("VersionInfo");
                FragmentManager fragmentManager=getFragmentManager();
                UpdataVersionDialogFragment updataVersionDialogFragment=UpdataVersionDialogFragment.getUpdateDialogFragment(versionInfo);
                updataVersionDialogFragment.show(fragmentManager,"dialog");
                break;
            case 4:

                break;
        }
    }

    public void showDialog(String s){
        FragmentManager fragmentManager=getFragmentManager();
        UpdataVersionDialogFragment updataVersionDialogFragment=UpdataVersionDialogFragment.getUpdateDialogFragment(s);
        updataVersionDialogFragment.show(fragmentManager,"");
    }
}
